package com.dingwei.lesyndrome.mvp.presenter;

import com.dingwei.lesyndrome.base.FailsBean;
import com.dingwei.lesyndrome.base.MyBaseBean;
import com.dingwei.lesyndrome.bean.GamCircleTypeBean;
import com.dingwei.lesyndrome.bean.HisCircleBean;
import com.dingwei.lesyndrome.custom.myCallback;
import com.dingwei.lesyndrome.mvp.view.Contract;
import com.lihao.baselibrary.base.BaseActivity;
import com.lihao.baselibrary.base.URLS;
import com.lihao.baselibrary.base.basePresenter;

import org.xutils.http.RequestParams;
import org.xutils.x;

/**
 * Created by lihao on 2017/9/12.
 */

public class HisCirclePresenter extends basePresenter {

    private Contract.HisCircleView hisCircleView;

    public HisCirclePresenter(Contract.HisCircleView view) {
        super(view);
        this.hisCircleView = view;
    }

    public void initData(int page, String mid, final boolean isRefresh, boolean isShowDialog) {
              RequestParams rp = new RequestParams(URLS.HOST+URLS.MEMBER_CIRCLE);
                    rp.addBodyParameter("mid",mid);
                    rp.addBodyParameter("cpage",page+"");
                    rp.addBodyParameter("sessionid",BaseActivity.value.getToken());

                    x.http().post(rp, new myCallback(BaseActivity.context, HisCircleBean.class,rp) {
                        @Override
                        public void back(MyBaseBean baseBean, String result) {
                            HisCircleBean bean = (HisCircleBean) baseBean;
                            if (isRefresh){
                                hisCircleView.onRefresh(bean);
                            }else {
                                hisCircleView.onLoadMore(bean);
                            }
                        }

                        @Override
                        public void fail(FailsBean baseBean, String result) {
                            hisCircleView.onFail();
                        }
                    });
    }


    public void like(String id, final int positon) {

        RequestParams rp = new RequestParams(URLS.HOST+URLS.OPAGREE);
        rp.addBodyParameter("cid", id);
        rp.addBodyParameter("sessionid", BaseActivity.value.getToken());
        x.http().post(rp, new myCallback(BaseActivity.context, MyBaseBean.class, rp) {
            @Override
            public void back(MyBaseBean baseBean, String result) {
                hisCircleView.likeSuccess(positon);
            }

            @Override
            public void fail(FailsBean baseBean, String result) {

            }
        });

    }
}
